package com.myk.game.gobangchess.signs;

import com.myk.game.gobangchess.Room;
import com.myk.game.gobangchess.Sign;
import com.myk.game.gobangchess.utils.SignsUtils;

import java.util.List;

/**
 * 缓存标记
 * refreshGameInfo时大量重复的静态的巨大的sign组合推荐用缓存名称代替。
 *    客户端存储所有新发现的缓存sign缓存到内存中或者可以缓存到本地文件中，可以大大节约流量。
 */
public class CacheSign extends Sign {

    /**
     * 用于检索缓存标记的来源，固定是room子类的类名
     */
    private final String roomCode;//房间名称

    /**
     *
     */
    private final String cacheName;//缓存的唯一名称

    /**
     *  缓存标记的版本，内容变化这里一定要更新
     */
    private final int cacheVersion;

    private final boolean isDiskCache; //是否开启硬盘缓存

    private String signContent; //缓存标记的内容

    /**
     * 注意，signs内容是动态的话，不要开启硬盘缓存，以免存储了太多无用缓存
     */
    public CacheSign(Room room,String name,int version, boolean isDisk, List<Sign> signs) {
        roomCode = room.getClass().getSimpleName();
        cacheName = name;
        cacheVersion = version;
        isDiskCache = isDisk;
        signContent = SignsUtils.signs2Str(signs);
    }

    @Override
    public String getSignInfo() {
        return type + "," + roomCode + "," + cacheName + "," + cacheVersion + "," + isDiskCache;
    }

    public String getSignContent() {
        return signContent;
    }

    public void setSignContent(List<Sign> signs){
        signContent = SignsUtils.signs2Str(signs);
    }
}
